home *** CD-ROM | disk | FTP | other *** search
- /*
- SNEWS 2.0
-
- rmgroup - remove newsgroups from the active file, and delete the files
-
-
- Copyright (C) 1991 John McCombs, Christchurch, NEW ZEALAND
- john@ahuriri.gen.nz
- PO Box 2708, Christchurch, NEW ZEALAND
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License, version 1, as
- published by the Free Software Foundation.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- See the file COPYING, which contains a copy of the GNU General
- Public License.
-
- */
-
- /*---------------------------- Source Control ------------------------------*/
-
- /*
- * $Id: RMGROUP.C,v 1.2 1994/02/05 18:48:42 gbj Exp user $
- */
-
- /****************************************************************************
- * 12 Jun 92 1.2 NJL Fix newsgroup text deletion *
- * 19 Jul 92 1.3 GT Extra parameter in find_news_group (). *
- * 26 Aug 92 1.4 MSM Snews 1.90 (no changes) *
- * 20 Mar 93 1.5 MSM Remove newsgroups from the ng file *
- * 3 Jun 93 1.6 MSM Snews 2 *
- * Make ng an optional file *
- * 2 Apr 94 1.7 MSM Suspend support *
- ****************************************************************************/
-
- #include "defs.h"
- #include "locking.h"
-
- #include <io.h>
- #include <fcntl.h>
-
- INFO my_stuff;
- SUSPEND *suspend_head;
-
-
- /*---------------------------- main ---------------------------------------*/
- void main(int argc, char *argv[])
- {
-
- /*
- * Delete a newsgroup.
- *
- * - delete the data and index files
- * - re-write the active file, without that newsgroup, saving the
- * old one as .bak
- *
- * This program could be structured to run faster, but I have tried
- * to do things so that if rmgroup croaks part way through, as little
- * damage will be done as possible.
- *
- */
-
- int i, sflag;
- char buf[256], buf2[256], *dir, *p;
- ACTIVE *gp;
- FILE *active_file, *new_active_file;
- int junk_flag; /* nz - posting to junk */
- SUSPEND *sus;
-
-
- if (argc > 1) {
-
- if (!load_stuff()) {
- fprintf(stderr, "Couldn't read rc info\n");
- }
-
- printf("Demon Internet Simple News Version %d.%02d [build %d]\n", rmj, rmm, rup);
- printf("Remove Newsgroups.\n");
-
- load_active_file();
- suspend_head = load_suspend();
- close_active();
-
-
- for (i = 1; i < argc; i++) {
-
- sflag = FALSE;
-
- /* check if on suspend list */
- sus = suspend_head;
- while (sus != NULL) {
- if (stricmp(sus->group, argv[i]) == 0) {
- fprintf(stderr, "rmgroup: %s is suspended, no action taken.\n",
- argv[i]);
- sflag = TRUE;
- }
- sus = sus->next;
- }
-
- /* check that the group exists - also prevent del of 'junk' */
-
- gp = find_news_group(argv[i], &junk_flag);
-
- if ((stricmp(gp->group, "junk") != 0) && (sflag == FALSE)) {
-
- /* form the directory name */
- dir = make_news_group_name(argv[i]);
- unlink(dir); /* was unlink(buf) */
- sprintf(buf, "%s.IDX", dir);
- unlink(buf);
-
- printf("rmgroup: Newsgroup %s: \n\tfiles gone... ", argv[i]);
-
- /* finally remove it from the active file */
- sprintf(buf, "%sactive", my_stuff.news_dir);
- if ((active_file = fopen(buf, "rb")) == NULL) {
- fprintf(stderr, "\nrmgroup: cannot open %s\n", buf);
- exit(1);
- }
- sprintf(buf, "%sactive.new", my_stuff.news_dir);
- if ((new_active_file = fopen(buf, "wb")) == NULL) {
- fprintf(stderr, "\nrmgroup: cannot create %s\n", buf);
- exit(1);
- }
- while (fgets(buf, 255, active_file) != NULL) {
- strcpy(buf2, buf);
- p = strtok(buf2, " \t");
- if (stricmp(argv[i], p) != 0) {
- if (fputs(buf, new_active_file) == EOF) {
- fprintf(stderr, "\nrmgroup: couldn't write new active file\n");
- }
- }
- else {
- printf("\n\tremoved from active file... ");
- }
- }
-
- fclose(active_file);
- fclose(new_active_file);
-
- /* rename the active to a .bak and the .new to the active */
-
- sprintf(buf, "%sactive.bak", my_stuff.news_dir);
- unlink(buf);
- sprintf(buf2, "%sactive", my_stuff.news_dir);
- rename(buf2, buf);
- sprintf(buf, "%sactive.new", my_stuff.news_dir);
- rename(buf, buf2);
-
- /* also remove it from the ng file */
- sprintf(buf, "%sng", my_stuff.news_dir);
- if ((active_file = fopen(buf, "rb")) == NULL) {
- /* fprintf(stderr, "\n\tpermission file ng does not exist\n"); */
- }
- else {
- sprintf(buf, "%sng.new", my_stuff.news_dir);
- if ((new_active_file = fopen(buf, "wb")) == NULL) {
- fprintf(stderr, "\nrmgroup: cannot create %s\n", buf);
- exit(1);
- }
- while (fgets(buf, 255, active_file) != NULL) {
- strcpy(buf2, buf);
- p = strtok(buf2, " \r\n");
- if (stricmp(argv[i], p) != 0) {
- if (fputs(buf, new_active_file) == EOF) {
- fprintf(stderr, "\nrmgroup: couldn't write new ng file\n");
- }
- }
- else {
- printf("\n\tremoved from ng file\n");
- }
- }
-
- fclose(active_file);
- fclose(new_active_file);
-
- /* rename the active to a .bak and the .new to the active */
-
- sprintf(buf, "%sng.bak", my_stuff.news_dir);
- unlink(buf);
- sprintf(buf2, "%sng", my_stuff.news_dir);
- rename(buf2, buf);
- sprintf(buf, "%sng.new", my_stuff.news_dir);
- rename(buf, buf2);
- }
- }
- else {
- if (sflag == FALSE)
- fprintf(stderr, "rmgroup: newsgroup %s not found\n", argv[1]);
- }
-
- }
-
- close_active_file();
- free_suspend(suspend_head);
-
- }
- else {
- printf("USAGE: rmgroup newsgroup names....\n");
- }
-
- }
-